package org.jasig.cas.client.util;

import java.io.InputStream;
import java.util.Properties;

/**
 * 
* Copyright: Copyright (c) 2020 LanRu-Caifu
* 
* @ClassName: PropertiesUtils.java
* @Description: 资源文件解析工具
*
* @version: v1.0.0
* @author: shaolinyu
* @date: 2020年4月21日 上午10:44:14
 */
public class PropertiesUtils {

	private static Properties props; 
	  
    private static void readProperties(String fileName) { 
    	InputStream fis = null;
    	try { 
            props = new Properties(); 
            fis =PropertiesUtils.class.getClassLoader().getResourceAsStream(fileName); 
            props.load(fis); 
        } catch (Exception e) { 
            e.printStackTrace(); 
        } finally{
        	if(fis != null){
        		try {
        			fis.close();
        		}catch(Exception e) { 
    	            e.printStackTrace(); 
    	        }
        	}
        	
        }
    } 
    
    /**
     * 根据文件名和属性名获取属性值
     * @author lidongyang
     * @param fileName
     * @param key
     * @return
     */
    public synchronized static String getProperty(String fileName,String key){ 
    	readProperties(fileName+".properties");
    	return props.getProperty(key); 
    } 
   
    public static void main(String[] args) {
        String value = PropertiesUtils.getProperty("cache-config", "redis.sentinel.master");
        System.out.println("value:"+value);
    }    

	
}
